from django.core.management.base import BaseCommand
from apps.role.models import SysRole

class Command(BaseCommand):
    help = 'Import default roles data into SysRole table'
    def handle(self, *args, **options):
        # 角色数据列表，元素字典
        roles_data = [
            {
                'name': '超级管理员',
                'code': 'SUPER_ADMIN',
                'remark': '具有所有权限的用户'
            },
            {
                'name': '管理员',
                'code': 'ADMIN',

                'remark': '具有系统管理权限'
            },
            {
                'name': '普通用户',
                'code': 'USER',
                'remark': '普通用户，访问系统功能'
            }
        ]

        # 插入数据
        role_objects = []
        for role_data in roles_data:
            role = SysRole(
                name=role_data['name'],
                code=role_data['code'],
                remark=role_data['remark']
            )
            role_objects.append(role)

        # 批量插入数据
        SysRole.objects.bulk_create(role_objects)

        self.stdout.write(self.style.SUCCESS(f'Successfully imported {len(role_objects)} roles'))